package cn.china.springboot.serviceimpl;

import com.github.pagehelper.PageHelper;
import entity.Product;
import mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Properties;

@Service
public class ProductServiceImpl implements ProductMapper {
@Autowired
ProductMapper pm;

    /**
     * 分页配置插件
     * @return
     */
    @Bean
    public PageHelper pageHelper() {
        System.out.println("MyBatisConfiguration.pageHelper()");
        PageHelper pageHelper = new PageHelper();
        Properties p = new Properties();
        p.setProperty("offsetAsPageNum", "true");
        p.setProperty("rowBoundsWithCount", "true");
        p.setProperty("reasonable", "true");
        pageHelper.setProperties(p);
        return pageHelper;
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return pm.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Product record) {
        return pm.insert(record);
    }

    @Override
    public int insertSelective(Product record) {
        return pm.insertSelective(record);
    }

    @Override
    public Product selectByPrimaryKey(Integer id) {
        return pm.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Product record) {
        return pm.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Product record) {
        return pm.updateByPrimaryKey(record);
    }

    /**
     * 查询菜品类型
     * @return
     */
    @Override
    public List<String> selectByProductType() {
        return pm.selectByProductType();
    }

    @Override
    public List<Product> selectByType(String type){
        return pm.selectByType(type);
    }

    public List<Product> selectByType(String type,Integer currentPage){
        PageHelper.startPage(currentPage, 2);
        return pm.selectByType(type);
    }

    @Override
    public int getCountByType(String type) {
        return pm.getCountByType(type);
    }
}
